package com.espirit.init.base;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.ModelField;
import com.espirit.eap.sa.Employee;

@Component
public class EmployeeBuilder extends ModelBuilderSupport {
	static final String CODE = "code";
	static final String NAME = "name";
	static final String TEL = "tel";
	static final String EMAIL = "email";
	static final String FAX = "fax";
	static final String MOBILE = "mobile";
	static final String DEPARTMENT = "department";
	static final String POSITION = "position";
	static final String FIXEDSALARY = "fixedSalary";
	
	
	@Override
	public boolean init() {
		return super.setClass(Employee.class, "Employee", "职员信息");
	}

	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(CODE, "Code", "编码");
		addModelField(NAME, "Name", "姓名");
		addModelField(TEL, "Tel", "电话");
		addModelField(EMAIL, "Email", "邮箱");
		addModelField(FAX, "Fax", "传真");
		addModelField(MOBILE, "Mobile", "手机");
		addModelField(POSITION, "Position", "职位");
		addModelField(DEPARTMENT, "Department", "部门");
		addModelField(FIXEDSALARY, "Fixed Salary", "基本工资");
	}
	
	@Override
	protected void setDefaultLayoutButtons() {
		super.setDefaultLayoutButtons();
	}
	
	@Override
	protected void addSearchFields() {
		super.addSearchField(convertPropertyToField(CODE, NAME, DEPARTMENT, POSITION));
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(CODE, NAME, DEPARTMENT, POSITION, TEL, MOBILE, FAX, EMAIL));
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(CODE, NAME, DEPARTMENT, POSITION, TEL, MOBILE, FAX, EMAIL));
	}
	
	@Override
	protected Element convertFieldToElement(ModelField mf, boolean isListLayout) {
		Element element = super.convertFieldToElement(mf, isListLayout);
		String name = element.getName();
//		if (!isListLayout){
//			if (DEPARTMENT.equals(name)){
//				setElementTreebox(element, "fn.service('espirit.eap.manager.department').allDepartments");
//			}
			if (name.equals(POSITION)){
				element.setTagName("dictselect");
				element.addExProperty("name", POSITION);
				element.addExProperty("type", POSITION);
			} 
//		}
		return element;
	}
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{NAME});
	}
}
